package com.insurance.modules.claim.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.insurance.common.common.ResponseData;
import com.insurance.common.enums.CommonEnum;
import com.insurance.common.utils.QueryList;
import com.insurance.modules.claim.service.ClaimCaseService;
import com.insurance.modules.claim.service.ClaimSettlementService;
import com.insurance.modules.claim.service.FileInfoService;
import com.insurance.modules.claim.service.PolicyInfoService;
import com.insurance.modules.claim.vo.request.CaseCloseRatioReq;
import com.insurance.modules.claim.vo.request.CasePayOutRatioReq;
import com.insurance.modules.claim.vo.response.CaseCloseRatioRsp;
import com.insurance.modules.claim.vo.response.DisabilityLevelReportRsp;
import com.insurance.modules.claim.vo.response.PayOutRatioRsp;
import com.insurance.modules.sys.controller.AbstractController;
import com.insurance.modules.sys.service.SysDeptService;
import com.insurance.modules.sys.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@Slf4j
@Api(tags = "报表中心")
@RestController
@RequestMapping("claim/report")
public class ReportController extends AbstractController {
    @Autowired
    private ClaimCaseService claimCaseService;

    @PostMapping("/queryPayOutRatio")
    @ApiOperation(value = "案件赔付率统计", notes = "案件赔付率统计")
    public ResponseData<Page<PayOutRatioRsp>> queryPayOutRatio(@RequestBody QueryList<CasePayOutRatioReq> param) {
        Long userId = getUserId();
        if (Objects.isNull(userId)) {
            return ResponseData.error(CommonEnum.USER_TOKEN_ERROR);
        }
        CasePayOutRatioReq req = param.getParams();
        Page<PayOutRatioRsp> page = new Page<>(param.getPage(), param.getPageSize());
        page = claimCaseService.queryPayOutRatio(page, req);
        return ResponseData.success(page);
    }

    @PostMapping("/queryAccidentTypeRatio")
    @ApiOperation(value = "身故类型赔付率统计", notes = "身故类型赔付率统计")
    public ResponseData<Page<PayOutRatioRsp>> queryAccidentTypeRatio(@RequestBody QueryList<CasePayOutRatioReq> param) {
        Long userId = getUserId();
        if (Objects.isNull(userId)) {
            return ResponseData.error(CommonEnum.USER_TOKEN_ERROR);
        }
        CasePayOutRatioReq req = param.getParams();
        Page<PayOutRatioRsp> page = new Page<>(param.getPage(), param.getPageSize());
        page = claimCaseService.queryAccidentTypeRatio(page, req);
        return ResponseData.success(page);
    }

    @PostMapping("/queryCaseCloseRatio")
    @ApiOperation(value = "案件结案率统计", notes = "案件结案率统计")
    public ResponseData<Page<CaseCloseRatioRsp>> queryCaseCloseRatio(@RequestBody QueryList<CaseCloseRatioReq> param) {
        Long userId = getUserId();
        if (Objects.isNull(userId)) {
            return ResponseData.error(CommonEnum.USER_TOKEN_ERROR);
        }
        CaseCloseRatioReq req = param.getParams();
        Page<CaseCloseRatioRsp> page = new Page<>(param.getPage(), param.getPageSize());
        page = claimCaseService.queryCaseCloseRatio(page, req);
        return ResponseData.success(page);
    }

    @PostMapping("/queryDisabilityLevelReport")
    @ApiOperation(value = "伤残等级赔付金额报表", notes = "伤残等级赔付金额报表")
    public ResponseData<Page<DisabilityLevelReportRsp>> queryDisabilityLevelReport(@RequestBody QueryList<CaseCloseRatioReq> param) {
        Long userId = getUserId();
        if (Objects.isNull(userId)) {
            return ResponseData.error(CommonEnum.USER_TOKEN_ERROR);
        }
        CaseCloseRatioReq req = param.getParams();
        Page<DisabilityLevelReportRsp> page = new Page<>(param.getPage(), param.getPageSize());
        page = claimCaseService.queryDisabilityLevelReport(page, req);
        return ResponseData.success(page);
    }

    @PostMapping("/querySelfPayAmount")
    @ApiOperation(value = "医疗自费金额报表", notes = "医疗自费金额报表")
    public ResponseData<Page<DisabilityLevelReportRsp>> querySelfPayAmountReport(@RequestBody QueryList<CaseCloseRatioReq> param) {
        Long userId = getUserId();
        if (Objects.isNull(userId)) {
            return ResponseData.error(CommonEnum.USER_TOKEN_ERROR);
        }
        CaseCloseRatioReq req = param.getParams();
        Page<DisabilityLevelReportRsp> page = new Page<>(param.getPage(), param.getPageSize());
        page = claimCaseService.querySelfPayAmountReport(page, req);
        return ResponseData.success(page);
    }

}

